import request from '@/utils/request'

/**
 *
 * @param {String} mobile 手机号
 * @param {string} code 验证码
 * @returns Promise
 */
export const login = (mobile, code) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: { mobile, code }
  })
}

/**
 * 发送验证码
 * @param {String} mobile 手机号
 * @returns Promise
 */
export const getCodeAPI = (mobile) => {
  return request({
    url: `/v1_0/sms/codes/${mobile}`
  })
}

/**
 * 获取用户个人信息
 * @returns
 */
export const getUserInfo = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

/**
 * 编辑用户照片资料（头像、身份证照片）
 * @param {*} file
 * @returns
 */
export const uploadAvator = (file) => {
  const fm = new FormData()
  fm.append('photo', file)
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fm
  })
}

/**
 * 编辑用户个人资料
 * @param {*} data
 * @returns
 */
export const getuploadProfile = (data) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}
/**
 * 关注用户
 * @param {*} target
 * @returns
 */
export const getFollowingsAPI = (data) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data
  })
}

/**
 * 取消关注
 * @returns
 */
export const DeleteFollowingAPI = (target) => {
  return request({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE'
  })
}
